package controllers

import (
	"github.com/astaxie/beego"
	"fmt"
)

type UploadFile struct {
	beego.Controller
}

func (this *UploadFile) Get() {
	this.TplName = "uploadfile.html"
}

func (this *UploadFile) Post() {
	file, fileHeader, err := this.GetFile("uploadname")
	if err != nil {
		this.Ctx.WriteString("文件上传失败")
	} else {
		defer file.Close()
		// 获取上传的文件的名称
		// 保存文件 注意第一个参数需要和name属性的值相同
		err := this.SaveToFile("uploadname", "static/uploadfile/" + fileHeader.Filename)
		if err != nil {
			fmt.Println("err = ", err)
			this.Ctx.WriteString("上传文件失败")
		} else {
			this.Ctx.WriteString("文件上传成功")
		}
	}
}
